package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ClassSchedule;
import cn.wolfcode.crm.query.ClassScheduleQueryObject;
import cn.wolfcode.crm.service.IClassScheduleService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("classSchedule")
public class ClassScheduleController {
    @Autowired
    public IClassScheduleService classScheduleService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"classSchedule:view", "课程表页面"}, logical = Logical.OR)
    public String view() {
        return "classschedule/classschedule";
    }

    @ResponseBody
    @RequestMapping("query")
    @RequiresPermissions(value = {"classSchedule:query", "课程表列表"}, logical = Logical.OR)
    public PageResult query(ClassScheduleQueryObject qo) {
        PageResult query = classScheduleService.query(qo);
        return query;
    }

    @ResponseBody
    @RequestMapping("saveOrUpdate")
    @RequiresPermissions(value = {"classSchedule:saveOrUpdate", "课程表增加或编辑"}, logical = Logical.OR)
    public JSONResult saveOrUpdate(ClassSchedule classSchedule) {
        try {
            if (classSchedule.getId() != null) {
                classScheduleService.updateByPrimaryKey(classSchedule);
            } else {
                classScheduleService.insert(classSchedule);
            }
            return JSONResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("操作失败");
        }
    }

}
